package collection;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.stream.Collectors;

public class StreamApiDemo2 {
    public static void main(String[] args) {
        Random rand = new Random();
        List<Integer> list = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你所需要的数组长度：");
        int len = scanner.nextInt();
        for (int i = 0; i < len; i++) {
            list.add(rand.nextInt(100));
        }
        System.out.println(list);
        Integer value = list.stream().min((e1,e2)->e1-e2).get(); //获取最小值
        System.out.println("最小值为:"+value);

        value = list.stream().max((e1,e2)->e1-e2).get(); //获取最大值
        System.out.println("最大值为:"+value);

        value = list.stream().reduce((e1,e2)->e1+e2).get(); //累加和
        System.out.println("累加和为:"+value);



    }
}
